#ifndef __FUNCTION_H
#define __FUNCTION_H

#include "stm32f0xx.h"

#define Abs(value)                 (((value)>=0)?(value):(0-(value)))
#define Constrain(input,low,high)  ((input)<(low)?(low):((input)>(high)?(high):(input))) 

#define PI    3.14159265f

// PID Part
typedef struct{
    float kp,ki,kd;         //PID参数
}PIDParam;

typedef struct{

    PIDParam pidParam;      //PID参数
    
    float lastError;        //上次误差
    float prevError;        //前次误差
    float output;           //输出
    float outMINLimit;      //输出最大值限制
    float outMAXLimit;      //输出最小值限制
    
}INCPIDController;          

typedef struct{

    PIDParam pidParam;      //PID参数
    
    float lastError;        //上次误差
    
    float iTerm;            //积分项
	float integrationLimit; //积分幅限
    
	float FilterPercent;    //一阶低通滤波系数(0,1]
    float output;           //输出
    float outMINLimit;      //输出最大值限制
    float outMAXLimit;      //输出最小值限制
    
}POSPIDController;  

void bubbleSort(uint16_t arr[], uint16_t len);

void INCPID_Update(INCPIDController *PID,float target,float input);
float POSPID_Update(POSPIDController *PID,float target,float input,float dt);


#endif
